package com.example.administrator.listviewdemo;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

/**
 * 数据库管理类
 * Created by Administrator on 2016/12/6 0006.
 */

public class DatabaseQuery {
   // private static Properties properties = new Properties();
    public static String driver = "com.mysql.jdbc.Driver";
    public static String url = "jdbc:mysql://583d434438e9b.gz.cdb.myqcloud.com:7993/LogHorizon";
    public static String user = "cdb_outerroot";
    public static String psw = "abc1230456";
    private Connection connection;
    private Statement statement;
   // private ResultSet  resultSet;
    public DatabaseQuery(){

    }
    public boolean  connectDatabase(){
        try {
            Class.forName(driver);
            connection = (Connection)DriverManager.getConnection(url,user,psw);

            if (!connection.isClosed()){

                return true;
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 查询数据库，返回结果
     * @param
     *      query:查询语句
     * @return
     */
    public ResultSet Query(String query){
        try {
            statement = connection.createStatement();
           return statement.executeQuery(query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public void closeCon(){
        try {
            connection.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
